package com.fivefox.constant;

import cn.hutool.core.collection.CollUtil;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

@Getter
public enum WebhookEvenEnum {
    /**
     * 应用信息
     */
    APP_OPEN("首次启用应用", "app", "app_open", "v1.0"),
    APP_STATUS_CHANGE("应用停启用", "app", "app_status_change", "v1.0"),
    APP_UNINSTALLED("应用卸载", "app", "app_uninstalled", "v1.0"),
    APP_TICKET("app_ticket 事件", "app", "app_ticket", "v1.0"),
    APP_VISIBILITY("应用可用性范围增加", "app", "application.application.visibility.added_v6", "v2.0"),
    /**
     * 用户管理
     */
    CONTACT_SCOPE_UPDATED("通讯录权限范围变更", "user", "contact.scope.updated_v3", "v2.0"),
    CONTACT_USER_CREATED("员工入职", "user", "contact.user.created_v3", "v2.0"),
    CONTACT_USER_DELETED("员工离职", "user", "contact.user.deleted_v3", "v2.0"),
    CONTACT_USER_UPDATED("员工信息被修改", "user", "contact.user.updated_v3", "v2.0"),
    /**
     * 部门管理
     */
    CONTACT_DEPARTMENT_CREATED("创建部门", "dept", "contact.department.created_v3", "v2.0"),
    CONTACT_DEPARTMENT_UPDATED("修改部门信息", "dept", "contact.department.updated_v3", "v2.0"),
    CONTACT_DEPARTMENT_DELETED("删除部门", "dept", "contact.department.deleted_v3", "v2.0"),
    /**
     * IM消息
     */
    IM_MESSAGE_RECEIVE("接收消息", "im", "im.message.receive_v1", "v2.0"),
    IM_BOT_ADD("机器人进群", "im", "im.chat.member.bot.added_v1", "v2.0");


    WebhookEvenEnum(String name, String type, String key, String version) {
        this.name = name;
        this.type = type;
        this.key = key;
        this.version = version;
    }

    private final String name;
    private final String type;
    private final String key;
    private final String version;

    private static Map<String, WebhookEvenEnum> map;
    public static WebhookEvenEnum get(String key) {
        if (CollUtil.isEmpty(map)) {
            map = Arrays.stream(values()).collect(Collectors.toMap(WebhookEvenEnum::getKey, e -> e));
        }
        return map.get(key);
    }
}
